#ifndef __DNS_WATCHER__
#define __DNS_WATCHER__

#include <windns.h>

static mm::dllwp_item_t wdns_watcher_apis [] = 
{
	
	{ "dnsapi.dll", "DnsQuery_A",		6 * 4 },
	{ "dnsapi.dll", "DnsQuery_W",		6 * 4 },
	{ "dnsapi.dll", "DnsQuery_UTF8",	6 * 4 },
	{ },
};

struct wdns_watcher : mm::basic_watcher_t
{
	wdns_watcher() : mm::basic_watcher_t( wdns_watcher_apis )
	{
	}
	//////////////////////////////////////////////////////////////////////////
	virtual size_t impl_before_call( size_t uid, hk::exec_context * pctx, size_t deny_count )
	{
		//if( deny_count ) return false;
		xv::xvalue_t _action;
		if( !_action.asObject() ) return true;
		//////////////////////////////////////////////////////////////////////////
		if( mm::is_api(uid, "DnsQuery_A") || mm::is_api(uid, "DnsQuery_UTF8") )
		{
			// DnsQuery_A
			PCSTR lpstrName = (PCSTR)pctx->args[0];
			_action["action"] = "r3:dns:dnsquery";
			_action["payload"]["doamin"] = lpstrName;
		}
		else if( mm::is_api(uid, "DnsQuery_W") )
		{
			PCWSTR lpstrName = (PCWSTR)pctx->args[0];
			_action["action"] = "r3:dns:dnsquery";
			_action["payload"]["doamin"] = tcs::ws_to_as(lpstrName);
		}
		else
		{
			return true;
		}
		throw_event( _action );
		return true;
	};

};


#endif